import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gongge/bean/PopBean.dart';
import 'package:gongge/pages/GamePage.dart';
import 'package:gongge/routers/router.dart';
import 'package:gongge/utils/AudioUtils.dart';
import '../main.dart';
import ' PanPageRouteBuilder.dart';
import '../generated/l10n.dart';
import '../pages/EveryDayGamePage.dart';
import '../wight/My.dart';
import 'ClickUtils.dart';
import 'CommUtils.dart';
import 'TimeUtils.dart';
import 'dart:math' as math;

class HelpUtils {
//每日挑战完成了
  Widget getcomplete(BuildContext context) {
    double size = CommUtils.getWidth(context);
    double hight = CommUtils.getHeight(context);
    return Column(
      children: [
        SizedBox(
          height: hight * 0.02,
        ),
        Container(
            width: double.infinity,
            height: hight * 0.06,
            decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage('assets/images/today_complete.png'),
                  fit: BoxFit.fill),
            ),
            child: Stack(
              children: [
                Align(
                  alignment: Alignment.center,
                  child: AutoSizeText(
                    S.of(context).today_challenges_complete,
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(13),
                      fontWeight: FontWeight.bold,
                      color: Color.fromRGBO(44, 51, 89, 100),
                      height: 0.7,
                    ),
                    maxLines: 2,
                    textAlign: TextAlign.center,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
                Align(
                  alignment: Alignment.centerRight,
                  child: Padding(
                    padding: EdgeInsets.only(right: 16.5),
                    child: Image.asset('assets/images/gou.png',
                        width: hight * 0.03,
                        height: hight * 0.03,
                        fit: BoxFit.cover),
                  ),
                )
              ],
            )),
        SizedBox(
          height: hight * 0.01,
        ),
        AutoSizeText(
          S.of(context).back_tomorrow,
          style: TextStyle(
            fontSize: ScreenUtil().setSp(13),
            color: Colors.white,
          ),
          maxLines: 1,
          textAlign: TextAlign.center,
          overflow: TextOverflow.ellipsis,
        ),
        SizedBox(
          height: ScreenUtil().setHeight(3),
        ),
      ],
    );
  }

//开始每日挑战
  Widget getnewGame(BuildContext context, {CallBack? callBack}) {
    // double width = CommUtils.getWidth(context);
    double hight = CommUtils.getHeight(context);
    return GestureDetector(
      onTap: () {
        AudioUtils.getInstance()?.play2("start_game.mp3");
        AudioUtils.getInstance()?.stopHomeBGm();
        // 开始每日模式 这里web会卡死
        //   navigatorToTargetPage(context, EveryDayGamePage(), callBack: callBack);
        startPageDown2(
          context,
          EveryDayGamePage(),
          calllBack: callBack,
        );
      },
      child: Stack(children: [
   
        Align(
          alignment: Alignment.center,
          child: Container(
            width: hight * 0.3,
            height: hight * 0.06,
            decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage('assets/images/start_game.png'),
                  fit: BoxFit.fill),
            ),
            child: Padding(
              padding: EdgeInsets.only(
                left: hight * 0.01,
                right: hight * 0.01,
                bottom: hight * 0.01,
              ),
              child: Row(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Container(
                    width: hight * 0.035,
                    height: hight * 0.035,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage('assets/images/box_frame.png'),
                          fit: BoxFit.contain),
                    ),
                    alignment: Alignment.center,
                    child: Transform.rotate(
                      angle: -math.pi / 4,
                      child: Image.asset(evearyGem[TimeUtils.CurrentMonth()],
                          width: hight * 0.025,
                          height: hight * 0.025,
                          fit: BoxFit.contain),
                    ),
                  ),
                  // //- math.pi / 4 向左旋转45度
                  // Container(
                  //   width: hight * 0.16,
                  //   height: hight* 0.16,
                  //   alignment: Alignment.center,
                  //   child: CommUtils.getText(
                  //       context, 15, S.of(context).start_game),
                  // ),
                 
                CommUtils.getText(
                           context, 15, S.of(context).start_game),
                
      //                    AutoSizeText(
      //  S.of(context).start_game,
      //   maxFontSize: 15,
      //   style: TextStyle(
      //     fontSize: 15,
      //     fontWeight: FontWeight.bold,
      //     color: textColor,
      //     shadows: <Shadow>[
      //       Shadow(
      //         offset: Offset(1, 3),
      //         blurRadius: 2.0,
      //         color: Colors.black,
      //       ),
      //     ],
      //     height: 1.2,
      //   ),
      //   maxLines: 1,
      //   textAlign: TextAlign.center,
      //   overflow: TextOverflow.ellipsis,
      // ),

                  Container(
                    width: hight * 0.035,
                    height: hight * 0.035,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage('assets/images/box_frame.png'),
                          fit: BoxFit.fill),
                    ),
                    alignment: Alignment.center,
                    child: Transform.rotate(
                      angle: -math.pi / 4,
                      child: Image.asset(evearyGem[TimeUtils.CurrentMonth()],
                          width: hight * 0.025,
                          height: hight * 0.025,
                          fit: BoxFit.contain),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ]),
    );
  }

  navigatorToTargetPage(BuildContext context, Widget wight,
      {CallBack? callBack}) async {
    //每日挑战游戏，带参数换回、
    if (ClickUtils.checkClick()) {
      final result = await Navigator.push(
          context,
          PanPageRouteBuilder(
              builder: (context) => wight, popDirection: AxisDirection.down));
      // print("开始回调:${result},${callBack}");
      AudioUtils.getInstance()?.startOrStopBgm();
      if (callBack != null && result != null) {
        //每日游戏里点击返回是空的
        callBack(result);
      }
    }
  }
}
